package com.sise.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sise.pojo.Teacher;
import com.sise.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Queue;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 彭海霞
 * @since 2020-06-13
 */
@Controller
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @PostMapping("/login")
    public String login(String tname, String password, Model model) {
        System.out.println(tname+"---"+password);
        if (!StringUtils.isEmpty(tname) && !StringUtils.isEmpty(password)) {
            QueryWrapper<Teacher> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("tname", tname).eq("password", password);
            Teacher teacher = teacherService.getOne(queryWrapper);
            model.addAttribute("teacher", teacher);
            return "index";
        }
        model.addAttribute("flag", "用户名或密码错误");
        return "login";
    }

}

